<?
$page_title="Change Password";
$mindex=3;
$profile_menu=1;
?>
<?include("includes/header.php") ?>
<?
$memberId=getMemberId();
if($memberId==0) kickOut();
if($_POST){
$memberInfo=qry_data("select * from bkitc_profiles where registrant_id=".$memberId);
$member=$memberInfo[0];
$old_pwd=$member["reg_password"];

$retflag=0;
if($old_pwd==$_REQUEST["txtpassold"]){
	$new_pwd=$_REQUEST["txtpassnew"];
	
	updateUserPassword($memberId,$new_pwd);
	$retflag=1;
	writeLog($member["full_name"]." changed password.");
}

}
?>
<div class="break"></div>
<?if($_POST && $retflag==0){ ?>
	<div class="errorBox" >Entered old password doesn't matched with the actual. Please check and try again.</div><br/>
<? }else if($_POST){?>
	<div class="msgBox" >Password changed successfully.</div><br/>
<? } ?>
<form method="post" action="password.php?mode=<?=$_GET["mode"]?>" name="frmPassword" onsubmit="return validateForm(this)" >
	
<div style="width:300px" class="label_12">

<b>Enter your Old Password </b>: <br/>
<input type="password" size="35" name="txtpassold" value="<?=$_POST["txtpassold"]?>" class="txtbox" maxlength="16"/><br/><br/>
<b>Enter your New Password </b>: <br/>
<input type="password" size="35" name="txtpassnew"  value="<?=$_POST["txtpassnew"]?>" class="txtbox" maxlength="16"/>
<br/><br/>
<b>Confirm your New Password </b>: <br/>
<input type="password" size="35" name="txtpasscnew"  value="<?=$_POST["txtpasscnew"]?>" class="txtbox" maxlength="16"/>
<br/><br/>

<input type="submit" value="Change Password" class="button" style="margin-right:1px"/>
<input type="button" value="Cancel" class="button" onclick="javascript:history.back()"/>

</div>
</form>
<?include("includes/footer.php") ?>

<script type="text/javascript">
function validateForm(vForm){

var msg="Please correct the errors:\n\n";
var eMode=0;

if(vForm.txtpassold.value==""){
eMode=1;
msg +=" Old Password field cannot be empty.\n\n";
}
if(vForm.txtpassnew.value==""){
eMode=1;
msg +=" New Password field cannot be empty.\n\n";
}
if(vForm.txtpasscnew.value==""){
eMode=1;
msg +=" Confirm Password field cannot be empty.\n\n";
}
if(vForm.txtpasscnew.value!="" && vForm.txtpassnew.value!="" && vForm.txtpasscnew.value!=vForm.txtpassnew.value){
eMode=1;
msg +="New Password and Confirm Password doesn't match. Please Check.\n\n";
}

if(eMode==1){
alert(msg);
return false;
}

}

</script>
